/*
 * sensors.c
 * Copyright (c) 2013 Maris BECS. All rights reserved.
 */

#include "sensors.h"
//#include "motors.h"


uint8_t rotary_read(void){
	uint8_t value = 0b00000000;
	if( !ioport_get_pin_level(ROTARY1) ){
		value|=0b00000001;
	}
	if( !ioport_get_pin_level(ROTARY2) ){
		value|=0b00000010;
	}
	if( !ioport_get_pin_level(ROTARY4) ){
		value|=0b00000100;
	}
	if( !ioport_get_pin_level(ROTARY8) ){
		value|=0b00001000;
	}
	// draw rotary number in top right corner
	if( value < 0xA ){ gfx_mono_draw_char( (48+value), 123, 0, &sysfont );} 
	else{ gfx_mono_draw_char( (55+value), 123, 0, &sysfont );}

	return value;
}


void sensorPower(bool on){
	if( on ){
		gpio_set_pin_group_high(POWER_PORT, 0b00111110);
	}else{
		gpio_set_pin_group_low(POWER_PORT, 0b00111110);
	}	
}


int8_t sensor_read(void){
	// inverted to compare easier
	return ~( ioport_get_port_level(PANASONIC_PORT, 0b11111111) );
}


int8_t line_read(void){
	return ioport_get_port_level(LINE_SENSOR_PORT, 0b00001111 );
};


void IR_status(void){
	// kill switch active
	if (HIGH == ioport_get_pin_level(KILL_SW)){
		gfx_mono_draw_string("KILL SW OFF", 53, 0, &sysfont);
	} else if (LOW == ioport_get_pin_level(KILL_SW)){
		gfx_mono_draw_string("KILL SW ON ", 53, 0, &sysfont);
		//drive(0,0);
	}
}


	